//
//  main.m
//  NSMutableString练习
//
//  Created by wenjim on 17/10/24.
//  Copyright © 2017年 WenJim. All rights reserved.
//

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
   
    
    /*
     需求：将3个xiaoningle拼接在一起，中间用空格隔开
     xiaoningle xiaoningle xiaoningle
     */
    
    NSString * subStr = @"xiaoningle";
    /*
    // xiaoningle
    NSString * newStr = [subStr stringByAppendingString:@" "];
    // xiaoningle xiaoningle
    newStr = [newStr stringByAppendingString:subStr];
    // xiaoningle xiaoningle
    newStr = [newStr stringByAppendingString:@" "];
    // xiaoningle xiaoningle xiaoningle
    newStr = [newStr stringByAppendingString:subStr];
    
    */
    
    /*
    // 注意：在开发中如果需要对字符串进行频繁的操作，不要使用不可变字符串
    NSString * newStr = [subStr stringByAppendingString:@" "];
    for (int i  = 0; i < 2; i++) {
        newStr = [newStr stringByAppendingString:subStr];
        newStr = [newStr stringByAppendingString:@" "];
    }
    
//    newStr = [newStr stringByReplacingCharactersInRange:NSMakeRange(newStr.length - 1, 1) withString:@" "];
    newStr = [newStr stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
    
    NSLog(@"newStr = %@",newStr);
    */
    
    NSMutableString * strM = [NSMutableString string];
    
    for (int i = 0; i < 3; i ++) {
        // 1.添加一个xiaoningle
        [strM appendString:subStr];
        // 2.添加一个空格
        [strM appendString:@" "];
    }
    
    [strM deleteCharactersInRange:NSMakeRange(strM.length - 1, 1)];
    
    NSLog(@"strM = |%@|",strM);
    
    return 0;
}
